package fragments;


import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.CardView;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.example.administrator.baseproject.BaseFragment;
import com.example.administrator.newxlmedical.BaseEnterActivity;
import com.example.administrator.newxlmedical.CountActivity;
import com.example.administrator.newxlmedical.EnterActivity;
import com.example.administrator.newxlmedical.InventoryActivity;
import com.example.administrator.newxlmedical.LogActivity;
import com.example.administrator.newxlmedical.MainActivity;
import com.example.administrator.newxlmedical.OpenDoorActivity;
import com.example.administrator.newxlmedical.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import constants.Constants;
import dialogs.SignOutDialog;
import utils.ActivityControl;
import utils.ActivityUtil;
import utils.ObjectSaveUtil;

/**
 * A simple {@link Fragment} subclass.
 */
public class MenuFragmet extends BaseFragment {

    @BindView(R.id.cv_first_menu_open_door)
    CardView cvOpenDoor;
    @BindView(R.id.cv_first_menu_log)
    CardView cvLog;
    @BindView(R.id.cv_first_menu_check)
    CardView cvCheck;
    @BindView(R.id.cv_first_menu_inventory)
    CardView cvInventory;
    @BindView(R.id.cv_first_menu_sign_out)
    CardView cvSignOut;
    public Unbinder unbinder;

    public MenuFragmet() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_menu_fragmet, container, false);
        unbinder = ButterKnife.bind(this, view);
        return view;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        unbinder.unbind();
    }

    @OnClick({R.id.cv_first_menu_open_door, R.id.cv_first_menu_log, R.id.cv_first_menu_check, R.id.cv_first_menu_inventory, R.id.cv_first_menu_sign_out})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.cv_first_menu_open_door:
                Intent intent1 = new Intent(mContext, OpenDoorActivity.class);
                intent1.putExtra(Constants.OPEN_DOOR, Constants.OPEN);
                startActivity(intent1);
                break;
            case R.id.cv_first_menu_log:
                ActivityUtil.jumpToActivity(mContext, LogActivity.class);
                break;
            case R.id.cv_first_menu_check:

                ActivityUtil.jumpToActivity(mContext, CountActivity.class);
                break;
            case R.id.cv_first_menu_inventory:
                Intent intent3 = new Intent(mContext, InventoryActivity.class);
                intent3.putExtra(Constants.OPEN_DOOR, Constants.INVENTORY);
                startActivity(intent3);
                break;
            case R.id.cv_first_menu_sign_out:
                // 退出登录
                SignOutDialog signOutDialog = new SignOutDialog(getActivity(), R.style.dialog);
                signOutDialog.setOwnerActivity(getActivity());
                signOutDialog.setOnClickListener(new SignOutDialog.OnClickListener() {
                    @Override
                    public void onClick(View v, Dialog dialog) {
                        ActivityUtil.jumpToActivity(getActivity(), EnterActivity.class);
                        ObjectSaveUtil.saveObject(mContext, "", Constants.USER_INFO_BEAN, Constants.USER_INFO_BEAN);
                        ActivityControl.finishAll();
                    }
                });
                signOutDialog.show();
                break;
        }
    }
}
